﻿<html>
	<head>
		<meta charset="utf-8"/>
		<style>
		
		.volume_col{
			text-align:right
		}
		.row, th{
			border-bottom:1px solid grey
		}
		td.row{
			padding:0 5px
		}
		pre{
			display:inline;
		}
		</style>
	</head>
<body>
<?php
	include "dbconfig.php";
	setlocale(LC_ALL,'cp1251', 'koi8-r', 'ru_RU.KOI8-R'); 
$mysqli = new mysqli($dbhost, $dbusername, $dbpassword, $dbscheme);
	if ($mysqli->connect_errno) {
	    echo "Не удалось подключиться к MySQL: " . $mysqli->connect_error;
	};
	if (!$mysqli->set_charset("utf8")) {
	    printf("Ошибка при загрузке набора символов utf8: %s\n", $mysqli->error);
	}
	$id=$_GET["listid"];
	$sql="select h.*,h.create_user_id create_user from product_list_header h where id=?";
	$stmt=$mysqli->prepare($sql);
	$stmt->bind_param("s", $id);
	if (!$stmt->execute()) {
    echo "Не удалось выполнить запрос 1: " . $mysqli->error;
		return;
	}
		
	$plan_header= $stmt->get_result();
	$stmt->close();
	$plan_header=$plan_header->fetch_assoc();
	$sql="select d.id,d.product_id,d.unit,d.volume,p.name product,d.comment"
					. " from product_list_details d"
					. " inner join product p on p.id=d.product_id"
					. " where list_id=?"
					. " order by product";
	$stmt=$mysqli->prepare($sql);
	$stmt->bind_param("s", $id);
	if (!$stmt->execute()) {
    echo "Не удалось выполнить запрос: " . $mysqli->error;
		return;
	}
	$plan_details=$stmt->get_result();
?>	
<h1><?php echo $plan_header['name']?></h1>
<table>
<tr>
	<td>Дата создания</td>
	<td><?php echo date("D d.m.Y H:i",strtotime($plan_header['create_date']))?>
	<?php echo strftime("%a %d.%m.%Y %H:%M",strtotime($plan_header['create_date'])) ?>
	</td>
</tr>
<tr>
	<td>Автор</td>
	<td><?php echo $plan_header['create_user']?></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
	<tr>
		<th>Продукт</th>
		<th>Количество</th>
		<th>&nbsp;</th>
		<th>Комментарий</th>
	</tr>
 <?php
while ($row = $plan_details->fetch_assoc()) {
	?>
	<tr styl>
		<td class="row"><?php echo $row['product'] ?></td>										
		<td class="row volume_col"><?php echo number_format($row['volume'],1) ?></td>
		<td class="row unit_col"><?php echo $row['unit'] ?></td>
		<td class="row"><pre><?php echo $row['comment'] ?>&nbsp;</pre></td>
	</tr>
	<?php
}
?>
</table>
</body>
</html>